var prefix = "/ant";

function showOperationExplain(util, pageName) {
    util.fixbar({
        bar1: false
        , bar2: true
        , css: {right: 50, bottom: 100}
        , bgcolor: '#393D49'
        , click: function (type) {
            if (type === 'bar2') {
                showLoading(true);
                $.ajax({
                    type: 'GET',
                    url: prefix + '/operation/getOperationExplainByPageName',
                    data: {pageName: pageName},
                    success: function (data) {
                        showLoading(false);
                        if (data.result) {
                            layer.open({
                                type: 1
                                ,
                                title: false //不显示标题栏
                                ,
                                closeBtn: false
                                ,
                                area: '800px;'
                                ,
                                shade: 0.8
                                ,
                                id: pageName + '-id' //设定一个id，防止重复弹出
                                ,
                                btn: ['去使用', '朕知道了']
                                ,
                                btnAlign: 'c'
                                ,
                                moveType: 1 //拖拽模式，0或者1
                                ,
                                content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">' + data.data.text + '</div>'
                                ,
                                success: function (layero) {
                                    /*var btn = layero.find('.layui-layer-btn');
                                    btn.find('.layui-layer-btn0').attr({
                                        href: 'http://www.layui.com/'
                                        ,target: '_blank'
                                    });*/
                                }
                            });
                        } else {
                            layer.alert(data.msg, {
                                title: '操作说明'
                            })
                        }
                    },
                    error: function (data) {
                        var msg = data.msg;
                        if (msg === '' || msg === null || msg === undefined) {
                            msg = '后台连接出现异常，请重试';
                        }
                        showLoading(false);
                        layer.alert(msg, {
                            title: '操作说明警告'
                        })
                    }
                });
            }
        }
    });
}

function showLoading(b) {
    if (b) {
        var loading = layer.load(1, {
            shade: [0.1, '#fff'] //0.1透明度的白色背景
        });
    } else {
        layer.closeAll('loading');
    }
}


function foodFilter() {
    var index = layer.open({
        type: 2,
        area: ['800px', '550px'],
        fixed: false,
        maxmin: true,
        shade: 0.8,
        content: [prefix + '/select/toSelectTable?tableUrl=' + prefix + '/select/findFood', 'no']
    });
    layer.full(index);
}

function dinnerFilter() {
    var index = layer.open({
        type: 2,
        area: ['800px', '550px'],
        fixed: false,
        maxmin: true,
        shade: 0.8,
        content: [prefix + '/select/toSelectTable?tableUrl=' + prefix + '/select/findDinner', 'no']
    });
    layer.full(index);
}

function materialFilter() {
    var index = layer.open({
        type: 2,
        area: ['800px', '550px'],
        fixed: false,
        maxmin: true,
        shade: 0.8,
        content: [prefix + '/select/toSelectTable?tableUrl=' + prefix + '/select/findMaterial', 'no']
    });
    layer.full(index);
}

function providerFilter() {
    var index = layer.open({
        type: 2,
        area: ['800px', '600px'],
        fixed: false,
        maxmin: true,
        shade: 0.8,
        content: [prefix + '/select/toSelectTable?tableUrl=' + prefix + '/select/findProvider', 'no']
    });
    layer.full(index);
}

function shopFilter() {
    var index = layer.open({
        type: 2,
        area: ['800px', '550px'],
        fixed: false,
        maxmin: true,
        shade: 0.8,
        content: [prefix + '/select/toSelectTable?tableUrl=' + prefix + '/select/findShop', 'no']
    });
    layer.full(index);
}


function userFilter() {
    var index = layer.open({
        type: 2,
        area: ['800px', '550px'],
        fixed: false,
        maxmin: true,
        shade: 0.8,
        content: [prefix + '/select/toSelectTable?tableUrl=' + prefix + '/select/findUser', 'no']
    });
    layer.full(index);
}

function warehouseFilter() {
    var index = layer.open({
        type: 2,
        area: ['800px', '600px'],
        fixed: false,
        maxmin: true,
        shade: 0.8,
        content: [prefix + '/select/toSelectTable?tableUrl=' + prefix + '/select/findWarehouse', 'no']
    });
    layer.full(index);
}

function selectWarehouse() {//add by gao.feng
    var index = layer.open({
        type: 2,
        area: ['800px', '600px'],
        fixed: false,
        maxmin: true,
        shade: 0.8,
        content: [prefix + '/select/toSelectTable?tableUrl=' + prefix + '/select/selectWarehouse', 'no']
    });
    layer.full(index);
}

function resetInput() {
    $('.layui-input').val('');

    if ($('#dinnerTypeName').length > 0) {
        $('#dinnerTypeName').val('');
    }

    if ($('#dinnerTypeId').length > 0) {
        $('#dinnerTypeId').val('');
    }

    if ($("#warehouseName").length > 0) {
        $("#warehouseName").val('');
    }

    if ($("#warehouseId").length > 0) {
        $("#warehouseId").val('');
    }

    if ($("#warehouseId2").length > 0) {
        $("#warehouseId2").val('');
    }

    if ($("#tranNo").length > 0) {
        $("#tranNo").val('');
    }

    if ($("#providerName").length > 0) {
        $("#providerName").val('');
    }

    if ($("#providerId").length > 0) {
        $("#providerId").val('');
    }

    if ($("#materialName").length > 0) {
        $("#materialName").val('');
    }

    if ($("#materialId").length > 0) {
        $("#materialId").val('');
    }

    if ($("#userName").length > 0) {
        $("#userName").val('');
    }

    if ($("#userId").length > 0) {
        $("#userId").val('');
    }

    if ($("#shopName").length > 0) {
        $("#shopName").val('');
    }

    if ($("#shopId").length > 0) {
        $("#shopId").val('');
    }

    if ($("#foodName").length > 0) {
        $("#foodName").val('');
    }

    if ($("#foodId").length > 0) {
        $("#foodId").val('');
    }

    if ($("#isCreateOrder").length > 0) {
        $("#isCreateOrder").get(0).selectedIndex = 0;
    }

    if ($("#isAudit").length > 0) {
        $("#isAudit").get(0).selectedIndex = 0;
    }

    if ($("#showZero").length > 0) {
        $("#showZero").get(0).selectedIndex = 1;
    }

    if ($('#sendMail').length > 0) {
        $("#sendMail").get(0).selectedIndex = 0;
    }

    if ($('#isInStorage').length > 0) {
        $("#isInStorage").get(0).selectedIndex = 0;
    }

    if ($('#isInOut').length > 0) {
        $("#isInOut").get(0).selectedIndex = 0;
    }

    if ($('#isFinish').length > 0) {
        $("#isFinish").get(0).selectedIndex = 0;
    }

    if ($('#search').length > 0) {
        $("#search").click();
    }


    if ($("#searchType").length > 0) {
        $("#searchType").get(0).selectedIndex = 0;
    }

    if ($("#searchProviderName").length > 0) {
        $("#searchProviderName").val('');
    }
}


Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}